﻿using System;
using System.Collections.Generic;
using KKSG;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000E24 RID: 3620
	internal class XChatMaqueeView : DlgBase<XChatMaqueeView, XChatMaqueeBehaviour>
	{
		// Token: 0x17003414 RID: 13332
		// (get) Token: 0x0600C27A RID: 49786 RVA: 0x0029D570 File Offset: 0x0029B770
		public override string fileName
		{
			get
			{
				return "GameSystem/ChatMaqueeDlg";
			}
		}

		// Token: 0x17003415 RID: 13333
		// (get) Token: 0x0600C27B RID: 49787 RVA: 0x0029D588 File Offset: 0x0029B788
		public override bool isHideChat
		{
			get
			{
				return false;
			}
		}

		// Token: 0x17003416 RID: 13334
		// (get) Token: 0x0600C27C RID: 49788 RVA: 0x0029D59C File Offset: 0x0029B79C
		public override int group
		{
			get
			{
				return 1;
			}
		}

		// Token: 0x17003417 RID: 13335
		// (get) Token: 0x0600C27D RID: 49789 RVA: 0x0029D5B0 File Offset: 0x0029B7B0
		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17003418 RID: 13336
		// (get) Token: 0x0600C27E RID: 49790 RVA: 0x0029D5C4 File Offset: 0x0029B7C4
		public override bool needOnTop
		{
			get
			{
				return true;
			}
		}

		// Token: 0x0600C27F RID: 49791 RVA: 0x0029D5D7 File Offset: 0x0029B7D7
		protected override void Init()
		{
			this._doc = XDocuments.GetSpecificDocument<XChatDocument>(XChatDocument.uuID);
			this._doc.ChatMaqueeView = this;
		}

		// Token: 0x0600C280 RID: 49792 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		public override void RegisterEvent()
		{
		}

		// Token: 0x0600C281 RID: 49793 RVA: 0x0029D5F7 File Offset: 0x0029B7F7
		protected override void OnShow()
		{
			base.OnShow();
		}

		// Token: 0x0600C282 RID: 49794 RVA: 0x0029D601 File Offset: 0x0029B801
		protected override void OnUnload()
		{
			this._doc = null;
			this.m_IsPlaying = false;
			this.m_MaqueeThird.Clear();
			base.OnUnload();
		}

		// Token: 0x0600C283 RID: 49795 RVA: 0x0029D625 File Offset: 0x0029B825
		public void ShowMaquee()
		{
			this.SetVisible(true, true);
		}

		// Token: 0x0600C284 RID: 49796 RVA: 0x0029D631 File Offset: 0x0029B831
		public void HideMaquee()
		{
			this.SetVisible(false, true);
		}

		// Token: 0x0600C285 RID: 49797 RVA: 0x0029D640 File Offset: 0x0029B840
		public void SetMaqueeSwitch(bool enable)
		{
			this.m_MaqueeSwitch = enable;
			bool flag = !base.IsLoaded();
			if (!flag)
			{
				bool flag2 = !enable;
				if (flag2)
				{
					this.m_IsPlaying = false;
					this.SetVisible(false, true);
				}
				else
				{
					this.PlayFinished();
				}
			}
		}

		// Token: 0x0600C286 RID: 49798 RVA: 0x0029D68C File Offset: 0x0029B88C
		public void ReceiveChatInfo(KKSG.ChatInfo chatinfo)
		{
			SceneType sceneType = XSingleton<XScene>.singleton.SceneType;
			bool flag = sceneType != SceneType.SCENE_HALL && sceneType != SceneType.SCENE_GUILD_HALL && sceneType != SceneType.SCENE_BATTLE && sceneType != SceneType.SCENE_FAMILYGARDEN && sceneType != SceneType.SCENE_ABYSSS && sceneType != SceneType.SCENE_TOWER && sceneType != SceneType.SCENE_NEST && sceneType != SceneType.SCENE_LEISURE;
			if (!flag)
			{
				bool flag2 = !this.m_MaqueeSwitch;
				if (!flag2)
				{
					bool flag3 = chatinfo.level <= XSingleton<XAttributeMgr>.singleton.XPlayerData.Level;
					if (flag3)
					{
						bool flag4 = chatinfo.channel == 5U;
						if (flag4)
						{
							this.AddMaqueeNormalInfo(chatinfo.info, 0f);
						}
						else
						{
							this.AddMaqueeNormalInfo(chatinfo.info, 5f);
						}
					}
				}
			}
		}

		// Token: 0x0600C287 RID: 49799 RVA: 0x0029D73C File Offset: 0x0029B93C
		public void AddMaqueeNormalInfo(string info, float stopTime)
		{
			bool flag = info == null;
			if (!flag)
			{
				this.ShowMaquee();
				MaqueeInfo maqueeInfo = new MaqueeInfo();
				maqueeInfo.content = info;
				maqueeInfo.playTimes = 1;
				maqueeInfo.showTime = stopTime;
				maqueeInfo.playSpeed = XSingleton<XGlobalConfig>.singleton.GetInt("MaqueeSpeed");
				this.m_MaqueeThird.Add(maqueeInfo);
				bool flag2 = !this.m_IsPlaying;
				if (flag2)
				{
					this.StartPlayMaquee(maqueeInfo);
				}
			}
		}

		// Token: 0x0600C288 RID: 49800 RVA: 0x0029D7B0 File Offset: 0x0029B9B0
		public void StartPlayMaquee(MaqueeInfo maquee)
		{
			string text = XLabelSymbolHelper.RemoveFormatInfo(maquee.content);
			bool flag = !base.IsVisible();
			if (flag)
			{
				this.SetVisible(true, true);
			}
			base.uiBehaviour.m_MaqueeText.SetText(text);
			Vector2 printSize = base.uiBehaviour.m_MaqueeText.GetPrintSize();
			base.uiBehaviour.m_MaqueeTextSymbol.InputText = text;
			this.m_PlayingMaquee = maquee;
			this.m_IsPlaying = true;
			this.m_CurShowTime = maquee.showTime;
			this.m_OffsetStart = (int)(printSize.x / 2f) + base.uiBehaviour.m_MaqueeBoard.spriteWidth / 2 + 20;
			this.m_OffsetEnd = -1 * this.m_OffsetStart;
			this.m_CurOffset = this.m_OffsetStart;
			base.uiBehaviour.m_MaqueeTween.PlayTween(true, -1f);
		}

		// Token: 0x0600C289 RID: 49801 RVA: 0x0029D88C File Offset: 0x0029BA8C
		public void UpdateMaquee(float delta)
		{
			bool flag = !this.m_IsPlaying || !base.IsVisible();
			if (!flag)
			{
				bool flag2 = this.m_CurOffset <= 0 && this.m_CurShowTime > 0f;
				if (flag2)
				{
					this.m_CurShowTime -= delta;
				}
				else
				{
					this.m_CurOffset -= (int)(delta * (float)this.m_PlayingMaquee.playSpeed);
					base.uiBehaviour.m_MaqueeText.gameObject.transform.localPosition = new Vector3((float)this.m_CurOffset, base.uiBehaviour.m_MaqueeText.gameObject.transform.localPosition.y, base.uiBehaviour.m_MaqueeText.gameObject.transform.localPosition.z);
					bool flag3 = this.m_CurOffset <= this.m_OffsetEnd;
					if (flag3)
					{
						this.PlayFinished();
					}
				}
			}
		}

		// Token: 0x0600C28A RID: 49802 RVA: 0x0029D988 File Offset: 0x0029BB88
		public void PlayFinished()
		{
			bool flag = this.m_PlayingMaquee == null;
			if (!flag)
			{
				bool flag2 = this.m_PlayingMaquee.playTimes > 1;
				if (flag2)
				{
					this.m_CurOffset = this.m_OffsetStart;
					this.m_PlayingMaquee.playTimes--;
					this.m_CurShowTime = this.m_PlayingMaquee.showTime;
				}
				else
				{
					this.m_MaqueeThird.RemoveAt(0);
					bool flag3 = this.m_MaqueeThird.Count > 0;
					if (flag3)
					{
						this.StartPlayMaquee(this.m_MaqueeThird[0]);
					}
					else
					{
						this.m_IsPlaying = false;
						base.uiBehaviour.m_MaqueeTween.PlayTween(false, -1f);
						base.UnLoad(false);
					}
				}
			}
		}

		// Token: 0x0400537B RID: 21371
		private XChatDocument _doc = null;

		// Token: 0x0400537C RID: 21372
		private bool m_IsPlaying;

		// Token: 0x0400537D RID: 21373
		private List<MaqueeInfo> m_MaqueeFirst = new List<MaqueeInfo>();

		// Token: 0x0400537E RID: 21374
		private List<MaqueeInfo> m_MaqueeSecond = new List<MaqueeInfo>();

		// Token: 0x0400537F RID: 21375
		private List<MaqueeInfo> m_MaqueeThird = new List<MaqueeInfo>();

		// Token: 0x04005380 RID: 21376
		private int m_OffsetStart = 0;

		// Token: 0x04005381 RID: 21377
		private int m_OffsetEnd = 0;

		// Token: 0x04005382 RID: 21378
		private int m_CurOffset = 0;

		// Token: 0x04005383 RID: 21379
		private float m_CurShowTime = 0f;

		// Token: 0x04005384 RID: 21380
		private bool m_MaqueeSwitch = true;

		// Token: 0x04005385 RID: 21381
		private MaqueeInfo m_PlayingMaquee;
	}
}
